import React, { useEffect } from 'react'
import * as echarts from 'echarts';
const BasicRadarChart = () => {
  var chartDom
  var myChart: any
  var option: any
  useEffect(() => {
    chartDom = document.getElementById('chart2')!;
    myChart = echarts.init(chartDom);
    option = {
      tooltip: {
        trigger: 'item'
      },
      legend: {
        top: '5%',
        left: 'center'
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          label: {
            show: false,
            position: 'center'
          },
          emphasis: {
            label: {
              show: true,
              fontSize: 40,
              fontWeight: 'bold'
            }
          },
          labelLine: {
            show: false
          },
          data: [
            { value: 1048, name: '抖音推广' },
            { value: 735, name: '微信推广' },
            { value: 580, name: '小红书推广' },
            { value: 484, name: '微博推广' },
            { value: 300, name: '替他途径' }
          ]
        }
      ]
    };
    option && myChart.setOption(option);
  }, [])
  const onResize = () => {
    option && myChart.setOption(option);
    myChart.resize()
  }
  window.addEventListener('resize', onResize)
  return (
    <div id="chart2" style={{ width: '100%', height: '100%', textAlign:'center'}}></div>
  )
}

export default BasicRadarChart